<?php

/**
 * @name TestController
 * @author duanChi <http://weibo.com/shijingye>
 * @desc 默认控制器
 * @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
 */
class TestController extends Yaf\Controller_Abstract {

	/** 
     * 默认动作
     * Yaf支持直接把Yaf_Request_Abstract::getParam()得到的同名参数作为Action的形参
     * 对于如下的例子, 当访问http://yourhost/dashboard/index/index/index/name/duanChi <http://weibo.com/shijingye> 的时候, 你就会发现不同
     */

	public function constAction() {
		var_dump(get_defined_constants());
		return FALSE;
	}
	public function envAction() {
        phpinfo();
        return FALSE;
    }
    public function lbsAction() {
        $res = _curl(
            'http://61.55.147.232/geolocation/lbs.get.php?data_type=json&access_secret_key=1ea19bd6b284ck57ed1e1fa6340cb41b998b72d3xo81',
            'datas=18603210527',
            _HTTP_POST,20,FALSE
        );
        var_dump($res);
        return FALSE;
    }
	public function routeAction() {
		$_REQUEST = init_request();
		//$this->setViewPath(_PROJECT_TEMPLATE_ROOT.DIRECTORY_SEPARATOR.'1307261330'.DIRECTORY_SEPARATOR.'www'.DIRECTORY_SEPARATOR);
		//print_r($this->getView()->getScriptpath());
		//print_r($_REQUEST);
		//echo _PROJECT_TEMPLATE_ROOT.DIRECTORY_SEPARATOR.'1307261330'.DIRECTORY_SEPARATOR.$_REQUEST['path'].'.html';
		return TRUE;
	}
	
	public function curlAction() {
		var_dump('86e590a30cccd7z415673d182e4ac4c1d2bd2af71bb9');
		//var_dump(_curl('http://61.55.147.232/auth/authorize.php?data_type=json&access_secret_key=sdfasfasfas','app_id=1354587129&authorization_code=43ceba8cc1444a8189b5faaced4c144d'),_HTTP_POST);
		return FALSE;
	}
	public function splitAction() {
		var_dump(preg_split('/(\r\n|\r|\n)+/' , "# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_hb.uninforun.com	FALSE	/	FALSE	0	ASP.NET_SessionId	ehnfxv3mnn0uxi55s4szc355
" ));
	}
	public function pregAction() {
		$pattern = "/^http:\/\/hb.uninforun.com\/sjz\/sysMemberLogin\/homepage.aspx/";
		$subject = 'http://hb.uninforun.com/sjz/sysMemberLogin/homepage.aspx?urlParm=c2hpamluZ3llJjIwMTItMTItNSAxNjowMjoyOCYzY2VjNjFhOGNjMTQ0YzkwOTA2OGRlNzM4YmZlMDcxYSYxMjQ1Jmh0dHAlM2ElMmYlMmZoYi51bmluZm9ydW4uY29tJTJmc2p6JTJmbmV3RGVmYXVsdC5hc3B4JkRhOTNLL1RURE5xSHYzM01yMVN3V0E9PQ==&cip=bIoWcV2xhYeG8a3d1Ely5g==';
		var_dump(preg_match($pattern, $subject));
		return FALSE;
	}
	
	public function iniAction() {
		$ini = \privateClass\Kernel\INI::read(dirname(dirname(__DIR__)).'/config.ini');
		var_dump($ini);
		return FALSE;
	}
	public function enctypeAction() {
		var_dump($_SERVER);
		return FALSE;
	}
	
	public function findAction() {
		$str = <<<HTML
<ul id="ul1">
    <li>item:<span>1</span></li>
    <li>item:<span>2</span></li>
</ul>
<ul id="ul2">
    <li>item:<span>3</span></li>
    <li>item:<span>4</span></li>
</ul>
HTML;
		$html = str_get_html($str);
		$_matches = [];
		$v = '#signinout';
		//preg_match_all('/(.+?(\[.+?\])*):(\S*)/','.cldiv input[style=width:200px;]',$_matches,PREG_SET_ORDER);
		preg_match_all('/(.+?):(eq|lt|gt|btw|first|last)\S*|([^:]+)|(.+?)\S*/', $v, $_matches, PREG_SET_ORDER);
		var_dump($_matches);
		
		$v = '#signinout tr:eq(2)';
		preg_match_all('/:(first|last|(eq|gt|lt|btw)\((-?\d{1,})\))/', $v, $_matches, PREG_SET_ORDER);
		var_dump($_matches);
		//(.+?)(:(first|last|(eq|gt|lt)\((-?\d{1,})\)))+
		//$v = 'value::hello world!';
		//$_matches = explode('value::', $v, 2);
		//var_dump($_matches);
		return FALSE;
	}
	public function countstrAction() {
        var_dump('#L0总部ECS短信下行测试，发送时间(服务器时间) 2013-04-28 15：00：30，短信内容(总部ECS测试目的为测试各省短信延时情况，本条短信大致为150字，测试结果会反馈到总部电渠宗总汇报，谢谢大家配合此次测试)，长短信，短信编号#L0');
        return FALSE;
    }
	public function cuAction() {
		$_req = "<r path='Eip' type='Charm.Eip.Mail.Rules.Mail.SearchMails' idx='0' count='30'><p type='acct' source='session'></p><p type='staff' source='session'>-1</p><p type='int' source='value'>-1</p><p type='int' source='value'>0</p><p type='string' source='value'>0</p><p type='string' source='value'></p></r>";
		$response = _curl('10.48.96.61/Page/Reflect.aspx?tmp=0.15568771128138614',$_req,_HTTP_POST,10,TRUE,['Cookie: ASP.NET_SessionId=u2znrcm2x3wbeensz522rxev'],FALSE,'','','ASP.NET_SessionId=u2znrcm2x3wbeensz522rxev');
		var_dump($response);
	}
	
	public function valueAction() {
		$v = 'value::hello world!';
		$_matches = explode('value::', $v, 2);
		var_dump($_matches);
		return FALSE;
	}
	
	public function reAction() {
		var_dump($_COOKIE);
		var_dump(file_get_contents('php://input'));
	}
	
	public function addAppAction() {
		
		var_dump(time());
		
		var_dump(sha1(time().mt_rand(0, 65535)));
		
		
		
		return FALSE;
	}
	
	public function parseAction() {
		$contents = <<<HTMLS
<div>
<li>aaaaa</li>
				<li>aaaaa</li>
				<li>aaasdf</li>
				<li>aaaaa</li>
				<li>aaaaa</li>
</div>		
HTMLS;
		$_conf = [
			'vars'	=>	[
				'test'	=>	'div li:lt(2)'
			],
		];
		//$html = str_get_html($contents);
		//$res = $html->find('div' ,0);
		$res = \privateClass\App\Data::get_vars($contents, $_conf);
		print_r($res);
		return FALSE;
	}
	
	public function xml2arrayAction() {
		$xml = <<<XML
<root>
				<strc ic="sd1">hkajdhfkadf
					<iox><![CDATA[ASDFASDFSFSDSDF]]></iox>
				</strc>
				<strc ic="sd2">啊啊啊啊啊啊啊啊
					
				</strc>
				
				</root>		
		
XML;
		//$array = \privateClass\Kernel\XML::to_array($xml);
		//$xml_handler = new \privateClass\App\XmlToArray($xml);
		$array = xml_to_array($xml,1);
		var_dump($array);
		return FALSE;
	}
	
	function timeAction() {
		echo mktime();
		return FALSE;
	}
	
	function utf8Action() {
		$string = '董维芳';
		$content = iconv("utf-8","gb2312//IGNORE",$string);
		//echo urlencode($content),'--',urlencode($string);
		echo rawurlencode(mb_convert_encoding($string.'##', 'gb2312','utf-8'));
		return FALSE;
	}
	
	function matchAction() {
		$_result = <<<uli
HTTP/1.1 200 OK
Date: Thu, 10 Jan 2013 09:10:44 GMT
Server: Apache/2.0.55 (Win32) PHP/4.3.10
X-Powered-By: PHP/4.3.10
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 1655
Content-Type: text/html; charset=gb2312	
uli;
		preg_match('/charset=(.*)/', $_result, $match);
		var_dump($match);
		return FALSE;
	}
	
	function jsonAction() {
		var_dump(json_decode('
{"dept":{"value":"","attribute":[]},"type":{"value":"\u884c\u653f\u4e2d\u5fc3\u901a\u77e5","attribute":{"align":"center"}},"title":{"value":"10\u670827\u65e5CS\u6d3b\u52a8\u901a\u77e5","attribute":{"href":"javascript:open_notify(\'192\');"}},"test":{"time":{"value":"2012-10-24","attribute":{"nowrap":"1","align":"center"}},"times":"hello world"}}',TRUE));
	}
	
	
	function binAction() {
		$str = '0011000000110000001101100011100000110000001100000011011100110100001100000011000000110111001101000011000000110000001101110011000000110000001100000011001101100001001100000011000000110010011001100011000000110000001100100110011000110000001100000011011100110101001100000011000000110110001101010011000000110000001101100011010000110000001100000011001001100101001100000011000000110111001101000011000000110000001101100011000100110000001100000011011001100110001100000011000000110110001100100011000000110000001101100011000100110000001100000011011001100110001100000011000000110010011001010011000000110000001101100011001100110000001100000011011001100110001100000011000000110110011001000011000000110000001100100110011000110000001100000011011100110001001100000011000000110111001101010011000000110000001101100011100100110000001100000011011101100001001100000011000000110011001100100011000000110000001100100110011000110000001100000011001101100110001100000011000000110011001101100011000000110000001100110011100000110000001100000011011000110011001100000011000000110110001100010011000000110000001100110011011100110000001100000011001100110100001100000011000000110011001110010011000000110000001101100011010000110000001100000011001100110110001100000011000000110101001101010011000000110000001101110011011000110000001100000011011000111001001100000011000000110100001110010011000000110000001101100011001100110000001100000011010000110010001100000011000000110101001101100011000000110000001101000011010100110000001100000011010000110111001100000011000000110100001100010011000000110000001101100011011100110000001100000011011000110011001100000011000000110100001101100011000000110000001101000011001100110000001100000011011001100011001100000011000000110100001101010011000000110000001101000110011000110000001100000011010000110010001100000011000000110110011000100011000000110000001101110011001100110000001100000011010000110100';
		$arr = str_split($str,8);
		$dec_arr = [];
		$strings = '';
		foreach ($arr as $v) {
			$strings .= chr(bindec($v));
		}
		//$strings = str_replace('00', '\\', $strings);
		var_dump($strings);
	}
	function strAction() {
		$str = '0068007400740070003a002f002f007500650064002e00740061006f00620061006f002e0063006f006d002f007100750069007a0032002f003f00360038006300610037003400390064003600550076006900490063004200560045004700410067006300460043006c0045004f0042006b00730044';
		$arr = str_split($str,4);
		$dec_arr = [];
		$strings = '';
		foreach ($arr as $v) {
			$strings .= '%'.str_replace('00', '', $v);;
		}
		//$strings = str_replace('00', '\\', $strings);
		var_dump($strings);
	}



}